/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Home.java
 *
 * Created on 29/09/2009, 20:57:52
 */

package cparc;

import Graficos.graficoCanFel;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDesktopPane;
import org.jfree.ui.RefineryUtilities;

/**
 *
 * @author Administrador
 */
public class Home extends javax.swing.JFrame {

    public static void showBrowser(String url) throws IOException,
                                             URISyntaxException {
    Desktop.getDesktop().browse(new URI(url));

}


    public void pesquisaBairros(){

        pesqBairro bairro = new pesqBairro();

        desk.add(bairro);

    }
     public void pesquisaAnimais(){

        pesqAnimal animal = new pesqAnimal();

        desk.add(animal);

    }

      public void pesquisaUsuario(){

        pesqUsuario usuario = new pesqUsuario();

        desk.add(usuario);
    }
       public void pesquisaRacas(){

        pesqRaca raca = new pesqRaca();

        desk.add(raca);
    }

    static JDesktopPane desk = new JDesktopPane();
    static String nomeUser = null;
    static String permUser = null;

    /** Creates new form Home */
    public Home(String nome, String perm) {
        initComponents();
        this.setLocationRelativeTo(null);

        welcome wel = new welcome();
        desk.add(wel);
        wel.setVisible(true);


       // coloca uma figura na barra de título da janela
        URL url = this.getClass().getResource("/images/wolf.png");
        Image imagemTitulo = Toolkit.getDefaultToolkit().getImage(url); 
        this.setIconImage(imagemTitulo);


        nomeUser = nome;
        permUser = perm;

        if(permUser.equalsIgnoreCase("User")){

            menuItemRaca.setVisible(false);
            menuItemBairro.setVisible(false);
            menuItemRuas.setVisible(false);
        }


        desk.setSize(this.getWidth(), this.getHeight());
        desk.setBackground(Color.white);
        desk.setVisible(true);
        add(desk);
        
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        menu_home = new javax.swing.JMenuBar();
        menu_arquivo = new javax.swing.JMenu();
        menuItemRaca = new javax.swing.JMenuItem();
        menuItemBairro = new javax.swing.JMenuItem();
        menuItemRuas = new javax.swing.JMenuItem();
        menuItemProp = new javax.swing.JMenuItem();
        menuItemAnim = new javax.swing.JMenuItem();
        menu_relatorio = new javax.swing.JMenu();
        menuItemRelat = new javax.swing.JMenuItem();
        logRacas = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        graficoLinha = new javax.swing.JMenuItem();
        menu_sobre = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Cadastro de População Animal de Rio Claro");
        setResizable(false);

        menu_arquivo.setText("Arquivo");
        menu_arquivo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_arquivoActionPerformed(evt);
            }
        });

        menuItemRaca.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        menuItemRaca.setText("Cadastro de Raças");
        menuItemRaca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemRacaActionPerformed(evt);
            }
        });
        menu_arquivo.add(menuItemRaca);

        menuItemBairro.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_MASK));
        menuItemBairro.setText("Cadastro de Bairros");
        menuItemBairro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemBairroActionPerformed(evt);
            }
        });
        menu_arquivo.add(menuItemBairro);

        menuItemRuas.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        menuItemRuas.setText("Cadastro de Ruas");
        menuItemRuas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemRuasActionPerformed(evt);
            }
        });
        menu_arquivo.add(menuItemRuas);

        menuItemProp.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
        menuItemProp.setText("Cadastro de Proprietários");
        menuItemProp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemPropActionPerformed(evt);
            }
        });
        menu_arquivo.add(menuItemProp);

        menuItemAnim.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
        menuItemAnim.setText("Cadastro de Animais");
        menuItemAnim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemAnimActionPerformed(evt);
            }
        });
        menu_arquivo.add(menuItemAnim);

        menu_home.add(menu_arquivo);

        menu_relatorio.setText("Relatório");
        menu_relatorio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_relatorioActionPerformed(evt);
            }
        });

        menuItemRelat.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        menuItemRelat.setText("Relatório de Animais por Rua");
        menuItemRelat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemRelatActionPerformed(evt);
            }
        });
        menu_relatorio.add(menuItemRelat);

        logRacas.setText("Log de Raças");
        logRacas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logRacasActionPerformed(evt);
            }
        });
        menu_relatorio.add(logRacas);

        jMenuItem3.setText("Gráfico de % entre Caninos e Felinos");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        menu_relatorio.add(jMenuItem3);

        graficoLinha.setText("Grafico de % Vacinas");
        graficoLinha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                graficoLinhaActionPerformed(evt);
            }
        });
        menu_relatorio.add(graficoLinha);

        menu_home.add(menu_relatorio);

        menu_sobre.setText("Suporte");

        jMenuItem2.setText("Solicitar Suporte");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        menu_sobre.add(jMenuItem2);

        menu_home.add(menu_sobre);

        jMenu1.setText("Exemplo");
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu1ActionPerformed(evt);
            }
        });

        jMenuItem1.setText("Layout");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        menu_home.add(jMenu1);

        setJMenuBar(menu_home);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1086, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 635, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void menu_arquivoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menu_arquivoActionPerformed
        
    }//GEN-LAST:event_menu_arquivoActionPerformed

    private void menuItemRacaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemRacaActionPerformed
        cadastroRaca cr = new cadastroRaca(nomeUser);
        //add(cr);
        desk.add(cr);
        cr.setVisible(true);
    }//GEN-LAST:event_menuItemRacaActionPerformed

    private void menuItemBairroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemBairroActionPerformed
        cadastroBairros cb  = new cadastroBairros();
        //add(cb);
        desk.add(cb);
        cb.setVisible(true);

    }//GEN-LAST:event_menuItemBairroActionPerformed

    private void menuItemPropActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemPropActionPerformed
        cadastroProp cp = null;
        try {
            cp = new cadastroProp();
            cp.setHome(this);
        } catch (SQLException ex) {
            Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
        }
        //add(cb);
        desk.add(cp);
        cp.setLocation(0,0);
        cp.setVisible(true);
    }//GEN-LAST:event_menuItemPropActionPerformed

    private void menuItemAnimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemAnimActionPerformed
        cadastroAnim ca = null;
       
        ca = new cadastroAnim();
        desk.add(ca);
        ca.setLocation(0, 0);
        ca.setVisible(true);
        
    }//GEN-LAST:event_menuItemAnimActionPerformed

    private void menuItemRuasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemRuasActionPerformed
        cadastroRuas cru = new cadastroRuas();
        desk.add(cru);
        cru.setVisible(true);
    }//GEN-LAST:event_menuItemRuasActionPerformed

    private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu1ActionPerformed
      
    }//GEN-LAST:event_jMenu1ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        Exemplos.exemploLayout exemplo = new Exemplos.exemploLayout();
        desk.add(exemplo);
        exemplo.setVisible(true);
        System.out.println("Layout");
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void menu_relatorioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menu_relatorioActionPerformed
     
    }//GEN-LAST:event_menu_relatorioActionPerformed

    private void logRacasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logRacasActionPerformed
             logRacas lrac = new logRacas();
        desk.add(lrac);
        lrac.setVisible(true);
    }//GEN-LAST:event_logRacasActionPerformed

    private void menuItemRelatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemRelatActionPerformed

        relatorioAnimaisporRua relat = new relatorioAnimaisporRua();
        desk.add(relat);
        relat.setVisible(true);
    }//GEN-LAST:event_menuItemRelatActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed

        String suporte = "http://localhost/teste/suporte.php?user=" + nomeUser;

       suporte = suporte.replaceAll(" ", "%20");
        try {
            showBrowser(suporte);
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        graficoCanFel graf = new graficoCanFel();
        graf.canFel();
       
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void graficoLinhaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graficoLinhaActionPerformed
       Graficos.graficoLinha vacin = new Graficos.graficoLinha("Vacinas");
         vacin.pack();
         RefineryUtilities.centerFrameOnScreen(vacin);
         vacin.setVisible(true);
    }//GEN-LAST:event_graficoLinhaActionPerformed

     
    /**
    * @param args the command line arguments
    */
   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem graficoLinha;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem logRacas;
    private javax.swing.JMenuItem menuItemAnim;
    private javax.swing.JMenuItem menuItemBairro;
    private javax.swing.JMenuItem menuItemProp;
    private javax.swing.JMenuItem menuItemRaca;
    private javax.swing.JMenuItem menuItemRelat;
    private javax.swing.JMenuItem menuItemRuas;
    private javax.swing.JMenu menu_arquivo;
    private javax.swing.JMenuBar menu_home;
    private javax.swing.JMenu menu_relatorio;
    private javax.swing.JMenu menu_sobre;
    // End of variables declaration//GEN-END:variables

}
